import { _decorator, Component, Node,Vec2, Sprite, Color, instantiate } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Plant')
export class Plant extends Component {
    attackRange = 1 // 攻击范围
    attackDamage = 10 // 每次攻击的伤害
    attackCooldown = 2 // 攻击冷却时间，秒
    attackTimer = 0 // 攻击计时器
    level = 1
    cost = 100
    isAlive = false
    blood = 100
    start() {

    }
    // 被攻击了
    onAttacked(damage, killCallback){
        this.blood -= damage;
        const sprite = this.node.getComponent(Sprite)
        const oColor = Color.WHITE
        
        sprite.color = Color.RED
        this.scheduleOnce(() => {
            sprite.color = oColor;
        }, 0.1);

        if(this.blood <= 0){
            this.isAlive = false
            this.node.destroy();
            killCallback && killCallback()
        }
    }
    onLoad () {
        // 可以在这里初始化植物的状态
    }

    update(deltaTime: number) {
 
    }

    onPlacedByPlayer() {
        // 植物被放置后，可以设置为激活状态
        this.isAlive = true;
        // 可以在这里添加植物放置的动画或其他效果
    }
}